package androidx.test.espresso.base;

import android.os.Build;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.view.MotionEvent;
import androidx.test.espresso.InjectEventSecurityException;
import androidx.test.espresso.core.internal.deps.guava.base.Preconditions;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class EventInjector {
    private static final String TAG = "EventInjector";
    private final EventInjectionStrategy injectionStrategy;

    /* JADX INFO: Access modifiers changed from: package-private */
    public EventInjector(EventInjectionStrategy injectionStrategy) {
        this.injectionStrategy = (EventInjectionStrategy) Preconditions.checkNotNull(injectionStrategy);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean injectKeyEvent(KeyEvent event) throws InjectEventSecurityException {
        KeyEvent keyEvent;
        long downTime = event.getDownTime();
        long eventTime = event.getEventTime();
        int action = event.getAction();
        int keyCode = event.getKeyCode();
        int repeatCount = event.getRepeatCount();
        int metaState = event.getMetaState();
        int deviceId = event.getDeviceId();
        int scanCode = event.getScanCode();
        int flags = event.getFlags();
        if (eventTime == 0) {
            eventTime = SystemClock.uptimeMillis();
        }
        long j = eventTime;
        long j2 = downTime == 0 ? j : downTime;
        if (Build.VERSION.SDK_INT < 9) {
            keyEvent = new KeyEvent(j2, j, action, keyCode, repeatCount, metaState, deviceId, scanCode, flags | 8);
        } else {
            keyEvent = new KeyEvent(j2, j, action, keyCode, repeatCount, metaState, deviceId, scanCode, flags | 8, event.getSource());
        }
        return this.injectionStrategy.injectKeyEvent(keyEvent);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean injectMotionEvent(MotionEvent event) throws InjectEventSecurityException {
        return this.injectionStrategy.injectMotionEvent(event, true);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean injectMotionEventAsync(MotionEvent event) throws InjectEventSecurityException {
        return this.injectionStrategy.injectMotionEvent(event, false);
    }
}
